#include "orders.h"

static struct OrderString
{
  int id;
  char order[64];
} orderStrings[] = {
  {0x000D0003, "smart"},
  {0x000D0004, "stop"},
  {0x000D0008, "<cancel>"},
  {0x000D000C, "setrally"},
  {0x000D000D, "getitem"},
  {0x000D000F, "attack"},
  {0x000D0010, "attackground"},
  {0x000D0011, "attackonce"},
  {0x000D0012, "move"},
  {0x000D0014, "AImove"},
  {0x000D0016, "patrol"},
  {0x000D0019, "holdposition"},
  {0x000D001A, "build"},
  {0x000D001B, "humanbuild"},
  {0x000D001C, "orcbuild"},
  {0x000D001D, "nightelfbuild"},
  {0x000D001E, "undeadbuild"},
  {0x000D001F, "resumebuild"},
  {0x000D0021, "dropitem"},
  {0x000D0022, "<swap item with 1>"},
  {0x000D0023, "<swap item with 2>"},
  {0x000D0024, "<swap item with 3>"},
  {0x000D0025, "<swap item with 4>"},
  {0x000D0026, "<swap item with 5>"},
  {0x000D0027, "<swap item with 6>"},
  {0x000D0028, "<use item 1>"},
  {0x000D0029, "<use item 2>"},
  {0x000D002A, "<use item 3>"},
  {0x000D002B, "<use item 4>"},
  {0x000D002C, "<use item 5>"},
  {0x000D002D, "<use item 6>"},
  {0x000D002F, "detectaoe"},
  {0x000D0031, "resumeharvesting"},
  {0x000D0032, "harvest"},
  {0x000D0034, "returnresources"},
  {0x000D0035, "autoharvestgold"},
  {0x000D0036, "autoharvestlumber"},
  {0x000D0037, "neutraldetectaoe"},
  {0x000D0038, "repair"},
  {0x000D0039, "repairon"},
  {0x000D003A, "repairoff"},
  {0x000D003B, "<revive hero 1>"},
  {0x000D003C, "<revive hero 2>"},
  {0x000D003D, "<revive hero 3>"},
  {0x000D003E, "<revive hero 4>"},
  {0x000D003F, "<revive hero 5>"},
  {0x000D0047, "revive"},
  {0x000D0048, "selfdestruct"},
  {0x000D0049, "selfdestructon"},
  {0x000D004A, "selfdestructoff"},
  {0x000D004B, "board"},
  {0x000D004C, "forceboard"},
  {0x000D004E, "load"},
  {0x000D004F, "unload"},
  {0x000D0050, "unloadall"},
  {0x000D0051, "unloadallinstant"},
  {0x000D0052, "loadcorpse"},
  {0x000D0053, "loadcorpseon"},
  {0x000D0054, "loadcorpseoff"},
  {0x000D0055, "loadcorpseinstant"},
  {0x000D0056, "unloadallcorpses"},
  {0x000D0057, "defend"},
  {0x000D0058, "undefend"},
  {0x000D0059, "dispel"},
  {0x000D005C, "flare"},
  {0x000D005F, "heal"},
  {0x000D0060, "healon"},
  {0x000D0061, "healoff"},
  {0x000D0062, "innerfire"},
  {0x000D0063, "innerfireon"},
  {0x000D0064, "innerfireoff"},
  {0x000D0065, "invisibility"},
  {0x000D0067, "militiaconvert"},
  {0x000D0068, "militia"},
  {0x000D0069, "militiaoff"},
  {0x000D006A, "polymorph"},
  {0x000D006B, "slow"},
  {0x000D006C, "slowon"},
  {0x000D006D, "slowoff"},
  {0x000D006F, "tankdroppilot"},
  {0x000D0070, "tankloadpilot"},
  {0x000D0071, "tankpilot"},
  {0x000D0072, "townbellon"},
  {0x000D0073, "townbelloff"},
  {0x000D0076, "avatar"},
  {0x000D0077, "unavatar"},
  {0x000D0079, "blizzard"},
  {0x000D007A, "divineshield"},
  {0x000D007B, "undivineshield"},
  {0x000D007C, "holybolt"},
  {0x000D007D, "massteleport"},
  {0x000D007E, "resurrection"},
  {0x000D007F, "thunderbolt"},
  {0x000D0080, "thunderclap"},
  {0x000D0081, "waterelemental"},
  {0x000D0083, "battlestations"},
  {0x000D0084, "berserk"},
  {0x000D0085, "bloodlust"},
  {0x000D0086, "bloodluston"},
  {0x000D0087, "bloodlustoff"},
  {0x000D0088, "devour"},
  {0x000D0089, "evileye"},
  {0x000D008A, "ensnare"},
  {0x000D008B, "ensnareon"},
  {0x000D008C, "ensnareoff"},
  {0x000D008D, "healingward"},
  {0x000D008E, "lightningshield"},
  {0x000D008F, "purge"},
  {0x000D0091, "standdown"},
  {0x000D0092, "stasistrap"},
  {0x000D0097, "chainlightning"},
  {0x000D0099, "earthquake"},
  {0x000D009A, "farsight"},
  {0x000D009B, "mirrorimage"},
  {0x000D009D, "shockwave"},
  {0x000D009E, "spiritwolf"},
  {0x000D009F, "stomp"},
  {0x000D00A0, "whirlwind"},
  {0x000D00A1, "windwalk"},
  {0x000D00A2, "unwindwalk"},
  {0x000D00A3, "ambush"},
  {0x000D00A4, "autodispel"},
  {0x000D00A5, "autodispelon"},
  {0x000D00A6, "autodispeloff"},
  {0x000D00A7, "barkskin"},
  {0x000D00A8, "barkskinon"},
  {0x000D00A9, "barkskinoff"},
  {0x000D00AA, "bearform"},
  {0x000D00AB, "unbearform"},
  {0x000D00AC, "corrosivebreath"},
  {0x000D00AE, "loadarcher"},
  {0x000D00AF, "mounthippogryph"},
  {0x000D00B0, "cyclone"},
  {0x000D00B1, "detonate"},
  {0x000D00B2, "eattree"},
  {0x000D00B3, "entangle"},
  {0x000D00B4, "entangleinstant"},
  {0x000D00B5, "faeriefire"},
  {0x000D00B6, "faeriefireon"},
  {0x000D00B7, "faeriefireoff"},
  {0x000D00BB, "ravenform"},
  {0x000D00BC, "unravenform"},
  {0x000D00BD, "recharge"},
  {0x000D00BE, "rechargeon"},
  {0x000D00BF, "rechargeoff"},
  {0x000D00C0, "rejuvination"},
  {0x000D00C1, "renew"},
  {0x000D00C2, "renewon"},
  {0x000D00C3, "renewoff"},
  {0x000D00C4, "roar"},
  {0x000D00C5, "root"},
  {0x000D00C6, "unroot"},
  {0x000D00CB, "entanglingroots"},
  {0x000D00CD, "flamingarrowstarg"},
  {0x000D00CE, "flamingarrows"},
  {0x000D00CF, "unflamingarrows"},
  {0x000D00D0, "forceofnature"},
  {0x000D00D1, "immolation"},
  {0x000D00D2, "unimmolation"},
  {0x000D00D3, "manaburn"},
  {0x000D00D4, "metamorphosis"},
  {0x000D00D5, "scout"},
  {0x000D00D6, "sentinel"},
  {0x000D00D7, "starfall"},
  {0x000D00D8, "tranquility"},
  {0x000D00D9, "acolyteharvest"},
  {0x000D00DA, "antimagicshell"},
  {0x000D00DB, "blight"},
  {0x000D00DC, "cannibalize"},
  {0x000D00DD, "cripple"},
  {0x000D00DE, "curse"},
  {0x000D00DF, "curseon"},
  {0x000D00E0, "curseoff"},
  {0x000D00E3, "freezingbreath"},
  {0x000D00E4, "possession"},
  {0x000D00E5, "raisedead"},
  {0x000D00E6, "raisedeadon"},
  {0x000D00E7, "raisedeadoff"},
  {0x000D00E8, "instant"},
  {0x000D00E9, "requestsacrifice"},
  {0x000D00EA, "restoration"},
  {0x000D00EB, "restorationon"},
  {0x000D00EC, "restorationoff"},
  {0x000D00ED, "sacrifice"},
  {0x000D00EE, "stoneform"},
  {0x000D00EF, "unstoneform"},
  {0x000D00F1, "unholyfrenzy"},
  {0x000D00F2, "unsummon"},
  {0x000D00F3, "web"},
  {0x000D00F4, "webon"},
  {0x000D00F5, "weboff"},
  {0x000D00F6, "wispharvest"},
  {0x000D00F7, "auraunholy"},
  {0x000D00F8, "auravampiric"},
  {0x000D00F9, "animatedead"},
  {0x000D00FA, "carrionswarm"},
  {0x000D00FB, "darkritual"},
  {0x000D00FC, "darksummoning"},
  {0x000D00FD, "deathanddecay"},
  {0x000D00FE, "deathcoil"},
  {0x000D00FF, "deathpact"},
  {0x000D0100, "dreadlordinferno"},
  {0x000D0101, "frostarmor"},
  {0x000D0102, "frostnova"},
  {0x000D0103, "sleep"},
  {0x000D0104, "darkconversion"},
  {0x000D0105, "darkportal"},
  {0x000D0106, "fingerofdeath"},
  {0x000D0107, "firebolt"},
  {0x000D0108, "inferno"},
  {0x000D0109, "gold2lumber"},
  {0x000D010A, "lumber2gold"},
  {0x000D010B, "spies"},
  {0x000D010D, "rainofchaos"},
  {0x000D010E, "rainoffire"},
  {0x000D010F, "request_hero"},
  {0x000D0110, "disassociate"},
  {0x000D0111, "revenge"},
  {0x000D0112, "soulpreservation"},
  {0x000D0113, "coldarrowstarg"},
  {0x000D0114, "coldarrows"},
  {0x000D0115, "uncoldarrows"},
  {0x000D0116, "creepanimatedead"},
  {0x000D0117, "creepdevour"},
  {0x000D0118, "creepheal"},
  {0x000D0119, "creephealon"},
  {0x000D011A, "creephealoff"},
  {0x000D011C, "creepthunderbolt"},
  {0x000D011D, "creepthunderclap"},
  {0x000D011E, "poisonarrowstarg"},
  {0x000D011F, "poisonarrows"},
  {0x000D0120, "unpoisonarrows"},
  {0x000D012E, "<reveal>"},
  {0x000D01E9, "frostarmoron"},
  {0x000D01EA, "frostarmoron"},
  {0x000D01EB, "frostarmoroff"},
  {0x000D01EE, "<tavern revive hero 1>"},
  {0x000D01EF, "<tavern revive hero 2>"},
  {0x000D01F0, "<tavern revive hero 3>"},
  {0x000D01F1, "<tavern revive hero 4>"},
  {0x000D01F2, "<tavern revive hero 5>"},
  {0x000D01F2, "awaken"},
  {0x000D01F3, "nagabuild"},
  {0x000D01F5, "mount"},
  {0x000D01F6, "dismount"},
  {0x000D01F9, "cloudoffog"},
  {0x000D01FA, "controlmagic"},
  {0x000D01FE, "magicdefense"},
  {0x000D01FF, "magicundefense"},
  {0x000D0200, "magicleash"},
  {0x000D0201, "phoenixfire"},
  {0x000D0202, "phoenixmorph"},
  {0x000D0203, "spellsteal"},
  {0x000D0204, "spellstealon"},
  {0x000D0205, "spellstealoff"},
  {0x000D0206, "banish"},
  {0x000D0207, "drain"},
  {0x000D0208, "flamestrike"},
  {0x000D0209, "summonphoenix"},
  {0x000D020A, "ancestralspirit"},
  {0x000D020B, "ancestralspirittarget"},
  {0x000D020D, "corporealform"},
  {0x000D020E, "uncorporealform"},
  {0x000D020F, "disenchant"},
  {0x000D0210, "etherealform"},
  {0x000D0211, "unetherealform"},
  {0x000D0213, "spiritlink"},
  {0x000D0214, "unstableconcoction"},
  {0x000D0215, "healingwave"},
  {0x000D0216, "hex"},
  {0x000D0217, "voodoo"},
  {0x000D0218, "ward"},
  {0x000D0219, "autoentangle"},
  {0x000D021A, "autoentangleinstant"},
  {0x000D021B, "coupletarget"},
  {0x000D021C, "coupleinstant"},
  {0x000D021D, "decouple"},
  {0x000D021F, "grabtree"},
  {0x000D0220, "manaflareon"},
  {0x000D0221, "manaflareoff"},
  {0x000D0222, "phaseshift"},
  {0x000D0223, "phaseshifton"},
  {0x000D0224, "phaseshiftoff"},
  {0x000D0225, "phaseshiftinstant"},
  {0x000D0228, "taunt"},
  {0x000D0229, "vengeance"},
  {0x000D022A, "vengeanceon"},
  {0x000D022B, "vengeanceoff"},
  {0x000D022C, "vengeanceinstant"},
  {0x000D022D, "blink"},
  {0x000D022E, "fanofknives"},
  {0x000D022F, "shadowstrike"},
  {0x000D0230, "spiritofvengeance"},
  {0x000D0231, "absorb"},
  {0x000D0233, "avengerform"},
  {0x000D0234, "unavengerform"},
  {0x000D0235, "burrow"},
  {0x000D0236, "unburrow"},
  {0x000D0238, "devourmagic"},
  {0x000D023B, "flamingattacktarg"},
  {0x000D023C, "flamingattack"},
  {0x000D023D, "unflamingattack"},
  {0x000D023E, "replenish"},
  {0x000D023F, "replenishon"},
  {0x000D0240, "replenishoff"},
  {0x000D0241, "replenishlife"},
  {0x000D0242, "replenishlifeon"},
  {0x000D0243, "replenishlifeoff"},
  {0x000D0244, "replenishmana"},
  {0x000D0245, "replenishmanaon"},
  {0x000D0246, "replenishmanaoff"},
  {0x000D0247, "carrionscarabs"},
  {0x000D0248, "carrionscarabson"},
  {0x000D0249, "carrionscarabsoff"},
  {0x000D024A, "carrionscarabsinstant"},
  {0x000D024B, "impale"},
  {0x000D024C, "locustswarm"},
  {0x000D0250, "breathoffrost"},
  {0x000D0251, "frenzy"},
  {0x000D0252, "frenzyon"},
  {0x000D0253, "frenzyoff"},
  {0x000D0254, "mechanicalcritter"},
  {0x000D0255, "mindrot"},
  {0x000D0256, "neutralinteract"},
  {0x000D0258, "preservation"},
  {0x000D0259, "sanctuary"},
  {0x000D025A, "shadowsight"},
  {0x000D025B, "spellshield"},
  {0x000D025C, "spellshieldaoe"},
  {0x000D025D, "spirittroll"},
  {0x000D025E, "steal"},
  {0x000D0260, "attributemodskill"},
  {0x000D0261, "blackarrow"},
  {0x000D0262, "blackarrowon"},
  {0x000D0263, "blackarrowoff"},
  {0x000D0264, "breathoffire"},
  {0x000D0265, "charm"},
  {0x000D0267, "doom"},
  {0x000D0269, "drunkenhaze"},
  {0x000D026A, "elementalfury"},
  {0x000D026B, "forkedlightning"},
  {0x000D026C, "howlofterror"},
  {0x000D026D, "manashieldon"},
  {0x000D026E, "manashieldoff"},
  {0x000D026F, "monsoon"},
  {0x000D0270, "silence"},
  {0x000D0271, "stampede"},
  {0x000D0272, "summongrizzly"},
  {0x000D0273, "summonquillbeast"},
  {0x000D0274, "summonwareagle"},
  {0x000D0275, "tornado"},
  {0x000D0276, "wateryminion"},
  {0x000D0277, "battleroar"},
  {0x000D0278, "channel"},
  {0x000D0279, "parasite"},
  {0x000D027A, "parasiteon"},
  {0x000D027B, "parasiteoff"},
  {0x000D027C, "submerge"},
  {0x000D027D, "unsubmerge"},
  {0x000D0296, "neutralspell"},
  {0x000D02AB, "militiaunconvert"},
  {0x000D02AC, "clusterrockets"},
  {0x000D02B0, "robogoblin"},
  {0x000D02B1, "unrobogoblin"},
  {0x000D02B2, "summonfactory"},
  {0x000D02B6, "acidbomb"},
  {0x000D02B7, "chemicalrage"},
  {0x000D02B8, "healingspray"},
  {0x000D02B9, "transmute"},
  {0x000D02BB, "lavamonster"},
  {0x000D02BC, "soulburn"},
  {0x000D02BD, "volcano"},
  {0x000D02BE, "incineratearrow"},
  {0x000D02BF, "incineratearrowon"},
  {0x000D02C0, "incineratearrowoff"}
};
static const int numOrderStrings = sizeof orderStrings / sizeof orderStrings[0];
char const* orderId2String(uint32 id)
{
  for (int i = 0; i < numOrderStrings; i++)
    if (orderStrings[i].id == id)
      return orderStrings[i].order;
  return NULL;
}
String id2String(uint32 id)
{
  String str = "";
  for (int i = 24; i >= 0; i -= 8)
    if ((id >> i) & 0xFF)
      str += char((id >> i) & 0xFF);
  return str;
}

bool isGoodId(uint32 id)
{
  for (int i = 0; i < 4; i++)
  {
    int m = int((unsigned char) (id & 0xFF));
    if ((m < '0' || m > '9') &&
        (m < 'A' || m > 'Z') &&
        (m < 'a' || m > 'z'))
      return false;
    id >>= 8;
  }
  return true;
}
